package jnpf.database.model.dto;

import jnpf.base.NoDataSourceBind;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * SQL参数传输对象
 *
 * @author JNPF开发平台组 GuanMengYu,YanYu
 * @version V3.2.0
 * @copyright 引迈信息技术有限公司
 * @date 2021/6/21
 */

@Data
@NoDataSourceBind
@AllArgsConstructor
public class PrepareSqlDTO {

    /**
     * conn连接
     */
    private Connection conn;

    /**
     * 执行的sql语句用占位符代替
     * 注意：一个对象只对应一条SQL
     */
    private String prepareSql;

    /**
     * sql对应占位符的值
     */
    private List<?> dataList;

    /**
     * 批量参数
     */
    private List<List<?>> multiDataList;

    /**
     * 是否是系统语句
     */
    private Boolean isSystemSql;

    /**
     * 是否显示别名
     */
    private Boolean isAlias;

    public PrepareSqlDTO(String prepareSql){
        this.prepareSql = prepareSql;
        this.dataList = new ArrayList<>();
        this.multiDataList = new ArrayList<>();
    }

    public PrepareSqlDTO(Connection conn, String prepareSql){
        this.conn = conn;
        this.prepareSql = prepareSql;
        this.dataList = new ArrayList<>();
        this.multiDataList = new ArrayList<>();
    }

    public PrepareSqlDTO(Connection conn, String prepareSql, Object ...objs){
        this.conn = conn;
        this.prepareSql = prepareSql;
        this.dataList = Arrays.asList(objs);
    }

    public PrepareSqlDTO(Connection conn, String prepareSql, List<?> prepareDataList){
        this.conn = conn;
        this.prepareSql = prepareSql;
        this.dataList = prepareDataList;
    }

    /* =================== 同一条语句，多个组参数 ======================== */

    public void addMultiData(List<?> prepareDataList){
        this.multiDataList.add(prepareDataList);
    }

    public void addMultiData(Object ...objs){
        this.multiDataList.add(Arrays.asList(objs));
    }

}
